﻿/*
 * Created by SharpDevelop.
 * User: rogerio
 * Date: 16/03/2010
 * Time: 16:02
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;

namespace csharp.rad.general
{
	/// <summary>
	/// Description of StockLog.
	/// </summary>
	public class StockLog : csharp.common.DefaultClass, csharp.common.IClass
	{
		#region Declarations variables
			  private string _user_id;
			  private string _warehouse_id;
			  private string _date_mov;
			  private string _type_mov;
			  private string _atual_value;
			  private string _old_value;
			  private string _quant;
			  private string _historic;
			  private string _product_id;
		#endregion
		
		public StockLog()
		{
			gsql.table = "common.stock_log";
			_sequence  = "common.stock_log_stock_log_id_seq";
			
			clear();
		}
		
		#region Gets and Sets
			public string user_id {
				get { return _user_id; }
				set { _user_id = value; }
			}
			
			public string warehouse_id {
				get { return _warehouse_id; }
				set { _warehouse_id = value; }
			}
			
			public string date_mov {
				get { return _date_mov; }
				set { _date_mov = value; }
			}
			
			public string type_mov {
				get { return _type_mov; }
				set { _type_mov = value; }
			}
			
			public string atual_value {
				get { return _atual_value; }
				set { _atual_value = value; }
			}
			
			public string old_value {
				get { return _old_value; }
				set { _old_value = value; }
			}
			
			public string quant {
				get { return _quant; }
				set { _quant = value; }
			}
			
			public string historic {
				get { return _historic; }
				set { _historic = value; }
			}
			
			public string product_id {
				get { return _product_id; }
				set { _product_id = value; }
			}
		#endregion
		
		#region Declarations methods
			public override void get(System.Data.DataRow dr)
			{
				_id           			  	= dr["stock_log_id"].ToString();
				_user_id 					= dr["stock_log_user_id"].ToString();
				_warehouse_id 				= dr["stock_log_warehouse_id"].ToString();
				_date_mov 					= dr["stock_log_date_mov"].ToString();
				_type_mov 					= dr["stock_log_type_mov"].ToString();
				_atual_value 				= dr["stock_log_atual_value"].ToString();
				_old_value 					= dr["stock_log_old_value"].ToString();
				_quant 						= dr["stock_log_quant"].ToString();
				_historic 					= dr["stock_log_historic"].ToString();
				_product_id					= dr["stock_log_product_id"].ToString();
			}
					
			public override void setGsql()
			{
				gsql.setValue( _id           			  	, "stock_log_id");
				gsql.setValue( _user_id 					, "stock_log_user_id");
				gsql.setValue( _warehouse_id 				, "stock_log_warehouse_id");
				gsql.setAsDateTime( _date_mov 				, "stock_log_date_mov");
				gsql.setValue( _type_mov 					, "stock_log_type_mov");
				gsql.setValue( _atual_value 				, "stock_log_atual_value");
				gsql.setValue( _old_value 					, "stock_log_old_value");
				gsql.setValue( _quant 						, "stock_log_quant");
				gsql.setValue( _historic 					, "stock_log_historic");
				gsql.setValue( _product_id					, "stock_log_product_id");
			}
			
			public void clear()
			{
				_id 			=  String.Empty ;
				_user_id 		=  String.Empty ;
				_warehouse_id 	=  String.Empty ;
				_date_mov 		=  String.Empty ;
				_type_mov 		=  String.Empty ;
				_atual_value 	=  String.Empty ;
				_old_value 		=  String.Empty ;
				_quant 			=  String.Empty ;
				_historic 		=  String.Empty ;
				_product_id 	=  String.Empty ;
			}
		#endregion
	}
	
	public class StockLogs : csharp.common.DefaultList, csharp.common.IList
	{
		public StockLogs()
		{
			gsql.table = "common.stock_log";
			clear();
		}
		
		#region Declarations methodos
			public StockLog get()
			{
				return (StockLog)items[index];
			}
			
			public StockLog get(Int32 index)
			{
				return (StockLog) items[index];
			}
			
			public bool fillList()
			{
				gsql.prepare();
				
				gsql.setValue("", "*");		
				
				return mountList();
			}
			
			public bool mountList()
			{
				int tam;
				if(!gsql.execute())
				{
					return false;
				}
				
				tam = gsql.getRowCount();
				items.Clear();
				
				for(int i = 0; i < tam; i++)
				{
					StockLog s = new StockLog();
					s.get(gsql.getRow(i));
					items.Add(s);
				}
				return true;
			}
		#endregion
	}
}
